﻿@model Resto.CostControl.Core.MaterialProcess
@{
    ViewBag.Title = "加工计划单编辑";
    Layout = "~/Views/Shared/_LayoutForm.cshtml";
}

@using (Html.AjaxBeginForm("Save"))
{ 
    <!-- 主表 --> 
    <div class="pageFormContent" style="width: 600px">
        @Html.HiddenFor(model => model.Id)
        @Html.DWZTextBoxFor(model => model.Code).Required()
        @Html.DWZDateFor(model => model.ProcessDate, "yyyy-MM-dd", new { style = "width:180px" }).Required()
        @Html.DWZTextBoxFor(model => model.TotalWeight).Required().Number()
        @Html.DWZDropDownListFor(model => model.Category, "MaterialCategory")
        @Html.DWZTextAreaFor(model => model.Remark)
        
    </div>
    <div class="clear">
    </div>
    <!-- 子表 --> 
    <div class="pageFormDetailList">
        @Html.Css("flexigrid", "tmpl", "list")
        @Html.Js("flexigrid", "tmpl", "list")
        @(        
 Html.DWZGridFor<Resto.CostControl.Core.MaterialProcessItem>()
        .Title("品名列表")
        .ID("MaterialList")
        .Action(@Url.Action("MaterialEditList"))
        .ExtParam(new { ParentId = "$('#Id').val()", Category = @ViewBag.Category ?? "", date = @ViewBag.Date ?? "" })
        .Width(580)
        .Height(130)
        .Columns(col =>
        {
            col.Bind(e => e.Id).IsKey().Sortable(false);
            col.Bind(e => e.Code).Width(60).Align(FlexiGridAlign.Left).Sortable(false);
            col.Bind(e => e.Name).Width(60).Align(FlexiGridAlign.Left).Sortable(false);
            col.Bind(e => e.RawMaterialId).EnumKey("Material").Width(60).Sortable(false);
            col.Bind(e => e.Category).EnumKey("MaterialCategory").Width(60).Sortable(false);
            col.Bind(e => e.ExpectedPickCount).Template(@Html.TextBox("ExpectedPickCount", "${ExpectedPickCount}", new { style = "text-align:right;width:56px" }).ToString()).Width(60).Sortable(false);
            //col.Bind(e => e.ActualPickCount).Width(60).Align(FlexiGridAlign.Right);
            col.Bind(e => e.ExpectedStorageCount).Template(@Html.TextBox("ExpectedStorageCount", "${ExpectedStorageCount}", new { style = "text-align:right;width:56px" }).ToString()).Width(60).Sortable(false);
            //col.Bind(e => e.ActualStorageCount).Width(60).Align(FlexiGridAlign.Right);
            col.Bind(e => e.Id, "操作", 60).Sortable(false)
               .Template(Url.GridLink("delete", "删除", "DeleteItem('${Id}')"));
        })
        .ShowCheckBox(false)
        .UsePager(false)
        .Buttons(btn =>
        {
            btn.Bind("Add", "选择品名", FlexiGridButtonType.Add).OnPress("SelectMaterial");
        })
    )
    @Html.Hidden("Category")
    </div>
}
@Html.FormBar()
<script type="text/javascript">
    function Additem(id) {
        var id = $("#Id").val();
        OpenModalDialog('@Url.Action("EditItem")?ParentId=' + id, { width: 480, height: 300, onclose: ReLoadMaterialList });
    }

    function SelectMaterial(e) {
        OpenModelWindow('@Url.Action("LookUp", "Dish")', { caption: "选择品名", width: 840, height: 400, onclose: function (MaterialData) {
            if (MaterialData) {
                $("#MaterialList").flexAddRows(MaterialData);
            }
        }
        });
    }

    function DeleteItem(Id) {
        $("#MaterialList")[0].childNodes[0].deleteRow();
        showLoadingMsg("删除成功！", { left: 300, top: 1 }, true, 3000);
    }

    function ReLoadMaterialList() {
        $("#MaterialList").flexReload();
    }
</script>